package com.piper.httputil;

import com.piper.config.UrlProperties;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class DefaultUriRoute extends UriRoute {

    @Override
    public String routeUri(HttpServletRequest request) {
        String uri = request.getRequestURI();
        System.out.println(uri);
        Map<String, String> urlMap = UrlProperties.map;
        String path = "";
        try {
            int lastIndex = uri.indexOf("/", 1);
            if (lastIndex == -1) {
                path = uri.substring(1);
            } else {
                path = uri.substring(1, uri.indexOf("/", 1));
            }
        } catch (StringIndexOutOfBoundsException e) {
            e.printStackTrace();
        }
        String uris = "";
        if (urlMap.containsKey(path)) {
            uris = urlMap.get(path) + uri.substring(path.length() + 1);
        } else {

            //转发到自己的工程

        }
        return uris;
    }
}
